package com.shigu;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.shigu.test.BaseSpringTest;
import com.shigu.user.OSS.OssIO;
import com.shigu.weixin.util.WxEntryDataUtil;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class SKUtest extends BaseSpringTest {
    @Autowired
    OssIO ossIO;

    @Test
    public void jsonArrayTest(){
        String s = "[{\"name\":\"颜色\",\"value\":\"蓝色，红色，品红色\"},{\"name\":\"花纹\",\"value\":\"猫，豹\"},{\"name\":\"尺码\",\"value\":\"S，M，L，XL\"}]";
        s=s.replaceAll("，",",");
        JSONArray jsonArray = JSONObject.parseArray(s);
        List< List<String> > list = new ArrayList<>();

        for (int i = 0; i <jsonArray.size() ; i++) {
            JSONObject obj = jsonArray.getJSONObject(i);
            String[] values = obj.getString("value").split(",");
          //  System.out.println(JSON.toJSONString(values));
            List<String> strs = new ArrayList<>(Arrays.asList(values));
            list.add(strs);
        }
        List<String> arr = combineAll(list);
        System.out.println(arr.size());
        System.out.println(JSON.toJSONString(arr));
    }

    public List<String> combineAll(List<List<String>> inputList){

        List<String> arr = new ArrayList<>();
        List a = inputList.get(0);
        List b = inputList.get(1);
        for (int i = 0; i <a.size() ; i++) {
            for (int j = 0; j <b.size() ; j++) {
                arr.add(a.get(i)+","+b.get(j));
            }
        }
        List<List<String>> newList  = new ArrayList<>();
        newList.add(arr);
        if (inputList.size() > 2){
            for (int i = 2; i < inputList.size() ; i++) {
                newList.add(inputList.get(i));
            }
            return combineAll(newList);
        }
        return arr;
    }

    @Test
    public void testPhone() throws Exception {
        String encrypdata="";
        String iv="";
        String sessionkey="";
        String str = WxEntryDataUtil.getDataJson(encrypdata, iv, sessionkey);
        System.out.println(str);

    }

    @Test
    public void oss() throws FileNotFoundException {
        FileInputStream is = new FileInputStream("C:\\Users\\过儿\\Desktop\\__UNI__B41533A_0702185648.apk");

        String filePath = "app/mall/package/2019/06/19/__UNI__B41533A_0619100804.apk";
        ossIO.deleteFile(filePath);
        String url = ossIO.uploadFile(is, filePath);
        System.out.println(url);
    }


    @Test
    public void img() throws FileNotFoundException {
//        for (int i = 1; i <8 ; i++) {
            FileInputStream is = new FileInputStream("D:/pic/qrRegist.png");

            String filePath = "app/mall/sns/1574141931769_qrRegist.png";
            ossIO.deleteFile(filePath);
            String url = ossIO.uploadFile(is, filePath);
            System.out.println(url);
//        }

    }
}
